home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / STRINGS.SWG / 0102_String A in String B.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  2KB  |  55 lines

  1. { Good'ol'times, when I could make my database programs in Clipper... Now I'm
  2. stuck with TP...:) Well, anyway, I remember a small symbol, $, which, when
  3. placed between two different strings checked if the first existed "in" the
  4. second. That's what this does. Checks if A exists in B. Upper/Lower case
  5. ignored (although it can be easily changed to take that into account).
  6. Useful to search by text keywords in databases. Returns True if A exists in B,
  7. false if it doesn't.
  8. Portuguese freeware, by Luis Evaristo Fonseca, Thunderball Software 1994
  9. }
  10.  
  11. {****************************************************************************}
  12. function upstring(a:string):string;
  13. var aux:string;
  14.     i:integer;                          {converts a string to uppercase}
  15. begin
  16.   aux:='';
  17.   for i := 1 to Length(a) do
  18.   begin
  19.       aux[0]:=chr(ord(aux[0])+1);
  20.       aux[i]:=upcase(a[i]);
  21.   end;
  22.   upstring:=aux;
  23. end;
  24.  
  25. {****************************************************************************}
  26.  
  27. function a_in_b(a,b:string):boolean;
  28. var conta,conta2,conta3:integer;
  29.     a1,b1:string;
  30.     aux:boolean;
  31. begin
  32.     aux:=false;                         {tests if a is in b, returns true if}
  33.     if length(a)<=length(b) then        {it is, false if it doesn't}
  34.     begin
  35.         a1:=upstring(a);
  36.         b1:=upstring(b);
  37.         for conta:=1 to length(b) do
  38.         begin
  39.             if b1[conta]=a1[1] then
  40.             begin
  41.                 aux:=true;
  42.                 for conta2:=1 to length(a) do
  43.                 begin
  44.                     if (a1[conta2]<>b1[conta2+conta-1]) then
  45.                        aux:=false;
  46.                 end;
  47.                 if aux=true then
  48.                     exit;
  49.             end;
  50.         end;
  51.     end;
  52.     a_in_b:=aux;
  53. end;
  54.  
  55.